package edu.gdkm.controller;

import edu.gdkm.annotation.LoginInterceptor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/springmvc")
public class FirstController {
    @RequestMapping("/show")
    public String show(Model model){
        model.addAttribute("msg","springmvc with annotation");
        return "index";
    }


    //    @RequestMapping(value="/show",method = {RequestMethod.GET})
    @GetMapping("/show")
    public String secondGet(){
        return "show";
    }
    //    @RequestMapping(value="/show",method = {RequestMethod.POST})
    @PostMapping("/show")
    public String secondPost(){
        return "show";
    }


    @LoginInterceptor
    @GetMapping("/goto")
    public String gotoJsp(Model model){
        System.out.println("你正在调用goto请求");
        model.addAttribute("msg","forward");
        //需要注意的是，方法返回的字符串一旦添加了“forward:”或“redirect:”前缀，那么视图解析器不再会为方法返回值拼接前缀和后缀了
        //forward转发可以到达本项目的所有资源（控制器、内部jsp、静态页面等等）
        return "forward:/WEB-INF/jsp/goto.jsp";
    }

    @LoginInterceptor
    @GetMapping("/gotor")
    public String gotoJsp2(Model model){
        model.addAttribute("msg","redirect");
        //可以重定向到本项目的控制器
        //return "redirect:first";
        //可以重定向到本项目的静态页面
        //return "redirect:/login.jsp";
        //可以重定向到任何的网络URL
        return "redirect:https://www.baidu.com";
    }
}
